package com.jz.community.sharesdk.share.view;

import android.app.Activity;
import android.support.design.widget.BottomSheetDialog;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.jz.community.basecomm.bean.ShareInfo;
import com.jz.community.sharesdk.R;
import com.jz.community.sharesdk.share.ShareApi;
import com.jz.community.basecomm.reflection.share.ShareClickListener;

/**
 * Created by Tony.Fan on 2018/6/15 14:11
 * <p>
 * 自定义分享弹框
 */
public class ShareDialog implements View.OnClickListener {
    private Activity mContext;
    private View view;
    private BottomSheetDialog bottomSheetDialog;
    private TextView shareWeChat;
    private TextView shareWeChatCircle;
    private TextView shareWechatSmallRoutine;
    private Button shareCancel;
    private ShareInfo shareInfo;
    private ShareClickListener shareClickListener;

    public ShareDialog(Activity context) {
        mContext = context;
        initView();
    }

    public ShareDialog(Activity context, ShareInfo shareInfo) {
        mContext = context;
        this.shareInfo = shareInfo;
        initView();
    }

    public ShareDialog(Activity context, ShareInfo shareInfo, ShareClickListener shareClickListener) {
        mContext = context;
        this.shareInfo = shareInfo;
        this.shareClickListener = shareClickListener;
        initView();
    }

    private void addListener() {
        shareCancel.setOnClickListener(this);
        shareWeChat.setOnClickListener(this);
        shareWeChatCircle.setOnClickListener(this);
        shareWechatSmallRoutine.setOnClickListener(this);
        showPopUp();
    }

    private void showPopUp() {
        bottomSheetDialog = new BottomSheetDialog(mContext);
        bottomSheetDialog.setContentView(view);
        bottomSheetDialog.show();
    }

    private void initView() {
        view = LayoutInflater.from(mContext).inflate(R.layout.dialog_share, null);
        shareWeChat = view.findViewById(R.id.share_wechat);
        shareWeChatCircle = view.findViewById(R.id.share_wechat_circle);
        shareWechatSmallRoutine = view.findViewById(R.id.share_wechat_smallroutine);
        shareCancel = view.findViewById(R.id.share_cancel);
        addListener();
    }

    @Override
    public void onClick(View v) {
        if (v.getId() == R.id.share_cancel) {
            bottomSheetDialog.dismiss();
        }
        if (v.getId() == R.id.share_wechat) {
            if (shareClickListener != null) {
                shareClickListener.shareClickResult();
            } else {
                ShareApi.getInstance().shareWeiXin(mContext, shareInfo);
            }
            bottomSheetDialog.dismiss();
        }

        if (v.getId() == R.id.share_wechat_circle) {
            ShareApi.getInstance().shareWeiXinCircle(mContext, shareInfo);
            bottomSheetDialog.dismiss();
        }

        /*if (v.getId() == R.id.share_wechat_smallroutine) {
            ShareApi.getInstance().shareWeiXinSmallRoutine(mContext, shareInfo);
            bottomSheetDialog.dismiss();
        }*/
    }
}
